#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>

//The data structure we use for passing more then one argument to the thread.
struct data
{
   int threadId;
   int totalNumberOfThreads;
};

//The function each thread runs.
void *PrintThread(void *threaddata)
{
   //makeing a pointer to a struct of type data.
   struct data *theData;
   //casting the data givin to the function to a struct of type data.
   theData = (struct data *) threaddata;
   int id;
   id = theData->threadId + 1;
   printf("thread %d/%d \n", id,theData->totalNumberOfThreads);
   pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
   int numThreads;
   numThreads = atoi(argv[1]);
   //printf("%d\n", numThreads); //To debug
   pthread_t threads[numThreads];
   
   int currentThread;
   int i;
   for(i=0; i<numThreads; i++)
   {
      struct data dataToThread;
      dataToThread.threadId = i;
      dataToThread.totalNumberOfThreads = numThreads;
      currentThread = pthread_create(&threads[i], NULL, PrintThread, (void *) &dataToThread);
      if (currentThread)
      {
         printf("error something didnt go the way it was suppose to! %d\n", currentThread);
         return(1);
      }
   }
   pthread_exit(NULL);
}

